﻿using Castle.Windsor;
using Castle.Windsor.Installer;
using NUnit.Framework;
using RuTracker.MVC.Core;
using RuTracker.WebSite;

namespace RuTrackerWebSiteTests
{
    [SetUpFixture]
    public class WholeSetup : IContainerAccessor
    {
        [SetUp]
        public void SetUp()
        {
            DbFacade.ClearDb();
            InitContainer();
        }

        [TearDown]
        public void TearDown()
        {
            DbFacade.ClearDb();
            ReleaseContainer();
        }

        private void InitContainer()
        {
            Container = Bootstrapper.BootstrapContainer()
                .Install(FromAssembly.This());

            RuTracker.MVC.Core.Container.SetContainerAccessor(this);
        }

        private void ReleaseContainer()
        {
            if (Container != null)
            {
                Container.Dispose();
                Container = null;
            }
        }


        public IWindsorContainer Container { get; private set; }
    }
}
